"""
1.列表.[]  有序，有索引，值可以重复/任意类型
2.字典{} 赋值叫{key-value} 无序 key是唯一的，一般都是字符串，value可以是任意类型
3.字典的查询
4.字典的添加与修改
5.字典的合并
6.字典的删除
7.获取所有的key、value、同时获取
8.成员运算符
"""

# 字典，赋值
message_dictionaries = {"身高":183, "name":"小明", "city":"chengdu"}
empty_dictionaries = {}
print(message_dictionaries)
print(empty_dictionaries)

# 3.查询 ---通过key去查询
# 1.字典（key）如果key不存在与字典当中则会报错
print(message_dictionaries["身高"])
# print(message_dictionaries["shenggao"]) 不存在会报错KeyError

# 2.字典.get（key） key不存在也不会报错
print(message_dictionaries.get("身高"))
# print(message_dictionaries.get("身高1"))  不存在则为None

# 4.添加key-value；修改key对应的value
# 1.字典[key] = value  如果存在key则是修改，如果不存在ke就是添加
message_dictionaries["age"] = 25
message_dictionaries["身高"] = 184
message_dictionaries["hobey"] = ["英语", "数学", "语文", "美术"]
message_dictionaries["intesting"] = {"city":["成都", "巴中"]}
print(message_dictionaries)

# 2.字典.setdefault(key,默认的value) 如果key不存在则添加，如果key存在则不做任何更改
message_dictionaries.setdefault("身高1", 186)
print(message_dictionaries)

# 5.字典的合并
# 旧字典.update（新字典）
new_dictionaries = {"sex":"boy","night":"134"}
message_dictionaries.update(new_dictionaries)
print(message_dictionaries)


# 6.字典的删除
# del字典[value]
del message_dictionaries["身高1"]
print(message_dictionaries)


# 7.获取字典的key  --字典.keys（）
print(message_dictionaries.keys())
# 获取字典的value  --字典.value()
print(message_dictionaries.values())
# 获取字典的key-value  --字典.items
print(message_dictionaries.items())

# 成员运算符
print("name" in message_dictionaries)
print("name" not in message_dictionaries)
print(("name","小明") in message_dictionaries.items())

# 字典长度
print(message_dictionaries.__len__())
print(len(message_dictionaries))